import { sleep } from '@/utils';
export default {
    render() {
        return this.$slots.default[0];
    },
    data() {
        return {
            scroll: 0
        };
    },
    computed: {},
    methods: {
        onInputFocus() {
            const input = this.$el.querySelector('input:focus');
            if (!input) return;
            const viewHeight = this.$el.offsetHeight;
            const inputTop = input.getBoundingClientRect().top;
            const contentTop = this.$el.children[0].getBoundingClientRect().top;
            document.title = inputTop - contentTop + ',' + viewHeight;
            this.$el.scrollTop = inputTop - contentTop - viewHeight / 2;
        }
    },
    async activated() {
        // 页面进来前,隐藏滚动，防止卡顿
        this.$el.style.overflow = 'hidden';
        this.$el.scrollTop = this.scroll;
        window.addEventListener('resize', this.onInputFocus);

        // 页面进后,允许滚动
        await sleep(400);
        this.$el.style.overflow = null;
    },
    deactivated() {
        this.scroll = this.$el.scrollTop;
        // 页面退出前,隐藏滚动，防止卡顿
        this.$el.style.overflow = 'hidden';
        window.removeEventListener('resize', this.onInputFocus);
    },
    beforeDestroy() {
        window.removeEventListener('resize', this.onInputFocus);
    },
    components: {}
};